package com.hope.controller;

import com.hope.domain.pojo.Address;
import com.hope.domain.pojo.Result;
import com.hope.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 马mq
 */
@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    @PostMapping("/create")
    public Result create(@RequestBody Address address) {
        System.out.println("address--create===="+address);
        return addressService.create(address);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id){
        System.out.println("delete--delete===="+id);
        return addressService.delete(id);
    }

    @GetMapping("/{id}")
    public Result getAddressById(@PathVariable Long id){
        System.out.println("address--getAddressById===="+id);
        return addressService.getAddressById(id);
    }

    @GetMapping()
    public Result<List<Address>> getAddressList(){
        System.out.println("address-getAddressList");
        return addressService.listByUserId();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Address address){
        System.out.println("address--update===="+address);
        return addressService.update(address);
    }

    @PostMapping("/default/{id}")
    public Result setDefault(@PathVariable Long id){
        System.out.println("address--update==id=="+id);
        return addressService.setDefault(id);
    }
}
